/**
 * 开票通知 - 编辑新增（选择出货单）
 * @author liuw
 * @date 2019/09/04
 */
define(function () {

    var self,
        app = win.app,
        doc = document,
        layui = win.layui,
        table_where = {},
        vueData = {
            isAdd: false,
            isCheck: false,
            type: 1,
            form: {
                GWECDOCNO : null,
                GWECDOCDATE : null,
                GWED004_NAME: null
            }
        },
        cols = [[
            { type:'checkbox',fixed: 'left'},
            { field: "GWECDOCNO", title: "出货单号",width: 180 },
            { field: "GWECSEQ", title: "项次",width: 100 },
            { field: "GWECDOCDATE", title: "单据日期",width: 100 },
            { field: "GWEC003", title: "订单号",width: 180 },
            { field: "GWEC101", title: "订单项次",width: 100 },
            { field: "GWEC004", title: "产品编号",width: 100 },
            { field: "GWAML003", title: "品名",width: 150 },
            { field: "GWAML004", title: "规格",width: 100 },
            { field: "GWAM008", title: "单位",width: 100 },
            { field: "GWAP100", title: "单价",width: 100 },
            { field: "GWEC005", width: 100,hide:true },
            { field: "GWEC005_NAME", title: "客户",width: 100 },
            { field: "GWEC009", title: "本次出货数量",width: 100 },
            { field: "GWED009_SUM", title: "已申请发票数量",width: 100 },
            { field: "GWEC011", title: "人员编号",width: 150 },
            { field: "GWEC011_NAME", title: "人员名称",width: 150 }
        ]],
        callObj,
        listData = null,
        table, gwei006EditAddTable,cb,layOpenIndex
    ;

    var Gwei006EditAdd = app.Module.extend({
            init: function () {
                self = this;
                self._super({
                    _tag: 'gwei006_edit_add',
                    _searchs: [
                        { id: 'gwei006_edit_add', tableId: 'gwei006_edit_add_table', datas:  cols[0] }
                    ],
                    _loadTplsFull: []
                }, win);
            },
            initTable: function () {
                layui.use(['table'], function () {
                    table = layui.table;
                    gwei006EditAddTable = table.render({
                        elem: app.getByid(doc, 'gwei006_edit_add_table'),
                        id: 'gwei006_edit_add_table',
                        url: g_ctxPath + 'crm/gwei006/getGwecData',
                        height:'240',
                        cols: cols,
                        data: listData,
                        totalRow: true,
                        page: true,
                        where: table_where,
                        done: function (res, curr, count) {

                        }

                    });
                });

            },

            //表格重载
            reloadTableCurr: function () {
                self._reloadTable({id: 'gwei006_edit_add_table', where: {
                        GWEC005: callObj.obj.GWED004,
                        GWECDOCDATE: vueData.form.GWECDOCDATE,
                        GWECDOCNO: vueData.form.GWECDOCNO,
                        GWECPLANT: callObj.obj.GWEDPLANT,
                        gweclist : callObj.obj.gweclist
                }});
            },

            _call: function (tagData) {
                callObj = tagData
                cb = callObj.cb;
                layOpenIndex = callObj.layOpenIndex;
                app.extendUpLow({
                    target: vueData.form,
                    res: callObj.obj,
                    reset: true
                });
                table_where.GWEDDOCNO = callObj.obj.GWEDDOCNO;
                table_where.GWEC005 = callObj.obj.GWED004;
                table_where.GWECPLANT = callObj.obj.GWEDPLANT;
                table_where.gweclist = callObj.obj.gweclist;

                self.initTable();
            },

            _ready: function () {
                table = layui.table;
                var vue = new Vue({
                    el: '#gwei006_edit_add',
                    data: vueData,
                    methods: {
                        cancel: function () {
                            layer.close(layer.index);
                        },
                        saveData: function () {
                            // 将选中的数据添加到编辑页面中的表格中
                            let checkStatusObj = table.checkStatus('gwei006_edit_add_table');
                            if(checkStatusObj.data.length == 0) {
                                app.showWarning("至少选择一笔数据进行保存");
                                return;
                            }
                            cb(checkStatusObj.data);
                            layer.close(layer.index);
                        },
                        queryData: function () {
                            self.reloadTableCurr();
                        },
                        resetData: function () {
                            vueData.form.GWECDOCDATE = '';
                            vueData.form.GWECDOCNO = '';
                        }
                    },
                    created: function () {
                        self._setEleIsReady('gwei006_edit_add');
                    }
                });
            },
            _lazy: function () {
                this._super();
            }
        })
    ;

    return new Gwei006EditAdd();

})
;